#ifndef __BSP_PID_H__
#define __BSP_PID_H__

#include "main.h"


/* PID结构体 */
typedef struct
{
  unsigned char PID_Channel_Val;    //PID通道地址
  float PID_Target_Val;       //目标值
  float PID_Actual_Val;       //实际值
  float PID_Err;              //偏差
  float PID_Err_Last;         //上一次偏差
  float PID_Integral_Val;    //积分值
  float PID_P,PID_I,PID_D;    //PID的比例、积分、微分系数
  float LPF;        //低通滤波系数
  float PID_dt;
}_PID_Typedef;

#define PID_Integral_Max            10000       //积分饱和限幅上限
#define PID_Integral_Min            -10000      //积分饱和限幅下限
#define PID_Output_Min              1000        //PID输出限幅上限
#define PID_Output_Max              -1000       //PID输出限幅下限

extern _PID_Typedef PID_Struct_Vertical;
extern _PID_Typedef PID_Struct_Velocity;
extern _PID_Typedef PID_Struct_Turn;


void PID_Struct_Init(_PID_Typedef *PID_Struct,unsigned char Channel);
void SET_PID_Target_Val(_PID_Typedef *PID_Struct, float value);
int GET_PID_Target_Val(_PID_Typedef *PID_Struct);
void SET_PID_Param(_PID_Typedef *PID_Struct, float P_Value, float I_Value, float D_Value);
float PID_Vertical(float Gyro_X);
float PID_Velocity(void);
float PID_Turn(float gyro_Z);

#endif
